﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CondominioWeb.Negocio;
using CondominioWeb.Dominio;
using CondominioWeb.Persistencia.NHibernate;

namespace CondominioWeb.Controllers
{
    public class ViviendaController : Controller
    {
        //Dependencias
        public AdministracionService administracionService { get; set; }
        


        // GET: /Vivienda/

        public ActionResult Index()
        {
            ICollection<Vivienda> modelo = administracionService.ListarTodasViviendas();
            return View(modelo);
        }

        //
        // GET: /Vivienda/Details/5

        public ActionResult Details(int Codigo)
        {
            Vivienda modelo = administracionService.ObtenerVivienda(Codigo);
            return View(modelo);
        }

        //
        // GET: /Vivienda/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Vivienda/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here
                if (ModelState.IsValid)
                {
                    administracionService.RegistrarVivienda(Int32.Parse((String)collection["Codigo_Vivienda"]),
                        (String)collection["Descripcion"],
                        Int32.Parse((String)collection["Numero_Vivienda"]),
                        Double.Parse((String)collection["Metraje"]),
                        1,
                        1,
                        1,
                        1,
                        (String)collection["Estado"]);
                }
                return RedirectToAction("Index");
            }
            catch
            {
                ModelState.AddModelError(String.Empty, "Error al crear vivienda");
                return View();
            }
        }
        
        //
        // GET: /Vivienda/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Vivienda/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Vivienda/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Vivienda/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}

